# coding=utf-8
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
使用discover()方法批量执行用例
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import unittest
from datetime import datetime
import HTMLTestRunner


# 测试用例存放路径
case_path = '../testSuits'

def get_allCase(self):
    suite = unittest.TestSuite()
    all_case = unittest.defaultTestLoader.discover(case_path, pattern="test_msydloan*.py")
    for case in all_case:
        suite.addTests(case)      # 把所有的测试用例添加进来
    #print(suite)
    return suite


if __name__ == '__main__':
    html_file = '../report/' + 'msydloan' + datetime.now().strftime('%Y-%m-%d %H%M%S') + '.html'  # 对html文件命名
    fp = open(html_file, 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='API测试报告', description='中移动项目接口测试情况')
    # 运行测试用例
    runner.run(get_allCase(1))
